System.register(["@angular/http", "ng2-layer", "@angular/core", "@angular/forms"], function (exports_1, context_1) {
    "use strict";
    var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
        var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
        if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
        else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
        return c > 3 && r && Object.defineProperty(target, key, r), r;
    };
    var __metadata = (this && this.__metadata) || function (k, v) {
        if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
    };
    var __moduleName = context_1 && context_1.id;
    var http_1, ng2_layer_1, core_1, core_2, forms_1, IndexSettingComp, BrowserImgComp, _a;
    return {
        setters: [
            function (http_1_1) {
                http_1 = http_1_1;
            },
            function (ng2_layer_1_1) {
                ng2_layer_1 = ng2_layer_1_1;
            },
            function (core_1_1) {
                core_1 = core_1_1;
                core_2 = core_1_1;
            },
            function (forms_1_1) {
                forms_1 = forms_1_1;
            }
        ],
        execute: function () {
            IndexSettingComp = (function () {
                function IndexSettingComp(http, layer, parent) {
                    var _this = this;
                    this.http = http;
                    this.layer = layer;
                    this.parent = parent;
                    this.indexData = {};
                    http.get({
                        search: {
                            m: "Admin",
                            c: "ApiSchool",
                            a: "initSetHtmlInfo"
                        }
                    }).then(function (data) {
                        _this.indexData = data.data;
                    });
                }
                IndexSettingComp.prototype.save = function () {
                    var _this = this;
                    this.http.post({
                        search: {
                            m: "Admin",
                            c: "ApiSchool",
                            a: "saveSetHtmlInfo"
                        },
                        body: this.indexData
                    }).then(function (data) {
                        _this.indexData = data.data;
                    });
                };
                IndexSettingComp.prototype.browserImg = function () {
                    this.layer.dialog({
                        title: "选择banner图片",
                        parent: this.parent,
                        dialogComponent: BrowserImgComp,
                        imports: [forms_1.FormsModule],
                        data: { parent: this }
                    });
                };
                return IndexSettingComp;
            }());
            IndexSettingComp = __decorate([
                core_2.Component({
                    selector: '.category',
                    templateUrl: 'template/router/indexSetting.html'
                }),
                __metadata("design:paramtypes", [http_1.Http, typeof (_a = typeof ng2_layer_1.NgLayer !== "undefined" && ng2_layer_1.NgLayer) === "function" && _a || Object, core_1.ViewContainerRef])
            ], IndexSettingComp);
            exports_1("IndexSettingComp", IndexSettingComp);
            BrowserImgComp = (function () {
                function BrowserImgComp(http) {
                    this.http = http;
                    this.selectData = null;
                    this.file = null;
                }
                BrowserImgComp.prototype.upload = function () {
                    var _this = this;
                    var payload = new FormData();
                    payload.append("avatar_file", this.file, this.file.name);
                    payload.append("avatar_data", JSON.stringify({
                        x: this.selectData.x,
                        y: this.selectData.y,
                        width: this.selectData.w,
                        height: this.selectData.h
                    }));
                    payload.append("avatar_src", "");
                    this.http.post({
                        search: {
                            m: "Home",
                            c: "Image",
                            a: "uploadImg",
                            type: "banner"
                        },
                        body: payload,
                        headers: { "Content-Type": null }
                    }).then(function (data) {
                        _this.indexData = data.data;
                    });
                };
                BrowserImgComp.prototype.previewImage = function (e) {
                    var _this = this;
                    var files = e.target.files;
                    if (files.length > 0) {
                        this.file = files[0];
                        var reader = new FileReader();
                        reader.onload = function (e) {
                            var img = document.getElementById("bannerImageCut");
                            img.src = e.target.result;
                            var jscrop;
                            $('#bannerImageCut').Jcrop({
                                onChange: function () {
                                    _this.selectData = jscrop.tellSelect();
                                },
                                onSelect: function () { },
                                aspectRatio: 3 / 1
                            }, function () {
                                jscrop = this;
                            });
                        };
                        reader.readAsDataURL(this.file);
                    }
                };
                return BrowserImgComp;
            }());
            BrowserImgComp = __decorate([
                core_2.Component({
                    templateUrl: "template/dialog/browserImage.html"
                }),
                __metadata("design:paramtypes", [http_1.Http])
            ], BrowserImgComp);
        }
    };
});
